import Vue from 'vue'
import VueRouter, { RouteConfig } from 'vue-router'

Vue.use(VueRouter)

const routes: Array<RouteConfig> = [
  {
    path: '/',
    name: 'Index',
    component: () => import('../views/Index.vue'),
    redirect: '/home',
    children: [
      {
        path: '/home',
        name: 'Home',
        meta: {
          title: "豪成生活馆"
        },
        component: () => import('../views/Home.vue')
      },
      {
        path: '/offline',
        name: 'OfflineMall',
        meta: {
          title: "线上商城"
        },
        component: () => import('../views/OfflineMall.vue')
      },
      {
        path: '/online',
        name: 'onLineMall',
        meta: {
          title: "线下商城"
        },
        component: () => import('../views/OnLineMall.vue')
      },
      {
        path: '/my',
        name: 'My',
        meta: {
          title: "我的"
        },
        component: () => import('../views/My.vue')
      }
    ]
  },
  {
    path: '/address/:id',
    name: 'Address',
    meta: {
      title: "地址编辑新增"
    },
    component: () => import('../views/Address.vue')
  },
  {
    path: '/addressList',
    name: 'AddressListPage',
    meta: {
      title: "地址列表"
    },
    component: () => import('../views/AddressListPage.vue')
  },
  {
    path: '/classMerchant/:id',
    name: 'ClassMerchant',
    meta: {
      title: "商户类别"
    },
    component: () => import('../views/ClassMerchant.vue')
  },
  {
    path: '/myInformation',
    name: 'MyInformation',
    meta: {
      title: "我的资料"
    },
    component: () => import('../views/MyInformation.vue')
  },
  {
    path: '/businessApplication',
    name: 'BusinessApplication',
    meta: {
      title: "商家入驻"
    },
    component: () => import('../views/BusinessApplication.vue')
  },
  {
    path: '/offlineNewProduct/:id',
    name: 'OfflineNewProduct',
    meta: {
      title: "线下新增商品"
    },
    component: () => import('../views/OfflineNewProduct.vue')
  },
  {
    path: '/onLineNewProduct/:id',
    name: 'OnLineNewProduct',
    meta: {
      title: "线上新增商品"
    },
    component: () => import('../views/OnLineNewProduct.vue')
  },
  {
    path: '/auditDetails/:id',
    name: 'AuditDetails',
    meta: {
      title: "审核商家"
    },
    component: () => import('../views/AuditDetails.vue')
  },
  {
    path: '/auditProducts/:id',
    name: 'AuditProducts',
    meta: {
      title: "审核商品"
    },
    component: () => import('../views/AuditProducts.vue')
  }
  ,
  {
    path: '/mySubordinates',
    name: 'MySubordinates',
    meta: {
      title: "我的团队"
    },
    component: () => import('../views/MySubordinates.vue')
  }
  ,
  {
    path: '/myWallet',
    name: 'MyWallet',
    meta: {
      title: "我的钱包"
    },
    component: () => import('../views/MyWallet.vue')
  },
  {
    path: '/toExamine',
    name: 'ToExamine',
    meta: {
      title: "审核列表"
    },
    component: () => import('../views/ToExamine.vue')
  }
  ,
  {
    path: '/merchantDetails/:id',
    name: 'MyCard',
    meta: {
      title: "我的会员卡"
    },
    component: () => import('../views/MyCard.vue')
  },
  {
    path: '/businessHomepage',
    name: 'BusinessHomepage',
    meta: {
      title: "商家首页"
    },
    component: () => import('../views/BusinessHomepage.vue')
  },
  {
    path: '/withdrawal/:id',
    name: 'Withdrawal',
    meta: {
      title: "提现"
    },
    component: () => import('../views/Withdrawal.vue')
  },
  {
    path: '/myOrder/:id',
    name: 'MyOrder',
    meta: {
      title: "我的订单"
    },
    component: () => import('../views/MyOrder.vue')
  },
  {
    path: '/writeOff/:id',
    name: 'WriteOff',
    meta: {
      title: "卡券详情"
    },
    component: () => import('../views/WriteOff.vue')
  },
  {
    path: '/codeCcanningVerification/:id',
    name: 'CodeCcanningVerification',
    meta: {
      title: "扫码核销"
    },
    component: () => import('../views/CodeCcanningVerification.vue')
  },
  {
    path: '/verification/:id',
    name: 'Verification',
    meta: {
      title: "已使用的券详情"
    },
    component: () => import('../views/Verification.vue')
  },
  {
    path: '/myCardBag',
    name: 'MyCardBag',
    meta: {
      title: "我的卡包"
    },
    component: () => import('../views/MyCardBag.vue')
  },
  {
    path: '/revenueRecords',
    name: 'RevenueRecords',
    meta: {
      title: "收益记录"
    },
    component: () => import('../views/RevenueRecords.vue')
  }
  , {
    path: '/onLineproductIist/:id',
    name: 'OnLineProductIist',
    meta: {
      title: "线上商品列表"
    },
    component: () => import('../views/OnLineProductIist.vue')
  }
  , {
    path: '/offlineproductIist/:id',
    name: 'OfflineProductIist',
    meta: {
      title: "线下商品列表"
    },
    component: () => import('../views/OfflineProductIist.vue')
  }
  , {
    path: '/offlineOrder',
    name: 'OfflineOrder',
    meta: {
      title: "线下订单"
    },
    component: () => import('../views/OfflineOrder.vue')
  }
  ,
  {
    path: '/onlineOrder',
    name: 'OnlineOrder',
    meta: {
      title: "线上订单"
    },
    component: () => import('../views/OnlineOrder.vue')
  }
  , {
    path: '/submitOrder/:id',
    name: 'SubmitOrder',
    meta: {
      title: "订单提交"
    },
    component: () => import('../views/SubmitOrder.vue')
  }, {
    path: '/commodityDetails/:id',
    name: 'CommodityDetails',
    meta: {
      title: "商品详情"
    },
    component: () => import('../views/CommodityDetails.vue')
  }, {
    path: '/myCard/:id',
    name: 'MerchantDetails',
    meta: {
      title: "商家详情"
    },
    component: () => import('../views/MerchantDetails.vue')
  },{
    path: '/agreement',
    name: 'Agreement',
    meta: {
      title: "购销协议"
    },
    component: () => import('../views/Agreement.vue')
  },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
router.beforeEach((to, from, next) => {
  document.title = to.meta.title
  next()
})

router.beforeEach((to, from, next) => {
  var u = navigator.userAgent;
  var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
  if (isiOS && to.path !== location.pathname) {
    location.assign(to.fullPath)
  } else {
    next()
  }
});



export default router
